package edu.zut.main.socket;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IPDemo {

    public static void main(String[] args) throws UnknownHostException {
        //ip：计算机的唯一表示   我们是通过ip可以锁定某一个主机（服务器）
        //根据 名称获取一个对应的ip对象
        InetAddress inetAddress = InetAddress.getByName("www.baidu.com");
        System.out.println("inetAddress = " + inetAddress);
        //获取主机名
        System.out.println(inetAddress.getHostName());
        //获取主机的远程地址
        System.out.println(inetAddress.getHostAddress());
        //获取本地主机信息
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println(localHost.getHostName());
        System.out.println(localHost.getHostAddress());

    }

}
